{template 'web/common/common'}
{template 'web/live/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<style type="text/css">
    .live-border{width: 170px;height: 155px;margin-top: 20px;margin-left: 20px;padding: 0;box-shadow: 4px 3px 4px -1px #c5b3b3;text-align: center;}
    .live-border .cover{width: 170px;height: 125px;}
    .live-border .title{width: 100%;height: 30px;line-height: 30px; overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: white;background: #757575;text-align: center;}
    .live-border .opeartion{width: 100%;height: 30px;position: absolute;background: #e4e4e4;text-align: right;top:0;display: none;}
    .live-border .opeartion img{width: 30px;height: 30px;z-index: 999;cursor: pointer;}
</style>
<div class="panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title">
            监控管理
        </h3>
    </div>
    <div class="panel-body">
        <div class="ibox-content">
            <!--<form action="{url 'site/entry/live',array('m'=>'kundian_farm','version_id'=>$_GPC['version_id'])}" id="searchform" method="post">-->
                <div class="row" style="padding: 0 15px;">
                    <!--<div class="col-sm-3">-->
                        <!--<input type="text" class="form-control" placeholder="标题" name="title" value="{$title}">-->
                    <!--</div>-->
                    <div class="col-sm-2">
                        <!--<button type="submit" class="btn btn-default " style="margin-right:5px;">查询</button>-->
                        <a class="btn btn-primary" href="{url 'site/entry/live',array('m'=>'kundian_farm','op'=>'live_edit','version_id'=>$_GPC['version_id'])}">增加</a>
                    </div>
                </div>
            <!--</form>-->
        </div>
        <form action="" method="post" class="form-horizontal form">
            <input type="hidden" name="token" value="{$_W['token']}">
            {loop $list $index $item}
             <div class="col-sm-2 live-border" title="所属分类：{$item['name']}">
                {if $item['cover']}
                    <img class="cover" src="{$item['cover']}">
                {else}
                    <img class="cover" src="{$_W['siteroot']}addons/kundian_farm/resource/img/bofnag.png">
                {/if}
                <div class="opeartion">
                    <a href="{url 'site/entry/live',array('m'=>'kundian_farm','op'=>'live_edit','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}">
                        <img src="{$_W['siteroot']}addons/kundian_farm/resource/img/live-edit.png"></a>
                    <img class="delete" data-id="{$item['id']}" src="{$_W['siteroot']}addons/kundian_farm/resource/img/live-del.png">
                </div>
                <div class="title">{$item['title']}</div>
             </div>
             {/loop}


            <!-- <div class="table-responsive panel-body">
                <table class="table-striped table-bordered table-hover dataTables-example table">
                    <thead class="navbar-inner">
                    <tr>
                        <th>ID</th>
                        <th>标题</th>
                        <th>封面</th>
                        <th>直播地址</th>
                        <th>分类名称</th>
                        <th>排序</th>
                        <th style="text-align:right;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $index $item}
                    <tr>
                        <td><div class="type-parent">{$item['id']}</div></td>
                        <td><div class="type-parent">{$item['title']}</div></td>
                        <td><div class="type-parent"><img src="{$item['cover']}" style="width: 60px;height: 60px;" alt=""></div></td>
                        <td><div class="type-parent">{$item['src']}</div></td>
                        <td><div class="type-parent">{$item['name']}</div></td>
                        <td><div class="type-parent">{$item['rank']}</div></td>

                        <td style="text-align:right;">
                            <a href="{url 'site/entry/live',array('m'=>'kundian_farm','op'=>'live_edit','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}" class="btn btn-primary btn-xs edit"><i class="fa fa-edit"></i>修改</a>
                            <a class="btn btn-danger btn-xs delete" data-id="{$item['id']}"><i class="fa fa-edit"></i>删除</a>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
                
            </div> -->
            <div style="clear: both;"></div>
            <div style="text-align: right;">
                    {$pager}
                </div>
        </form>


    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){

            $(".live-border").mouseover(function(){
                $(this).children('.opeartion').show();
            })

            $(".live-border").mouseout(function(){
                $(this).children('.opeartion').hide();
            })

            //改变状态
            $(".js-switch").change(function(){
                var status;
                var that=$(this);
                if($(this).is(":checked")){
                    status=1;
                }else{
                    status=0;
                }
                var id=$(this).attr("data-id");
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'statusChange','version_id'=>$_GPC['version_id'])}",
                    data:{id:id,status:status},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            swal('操作成功!', '操作成功!', 'success');
                        }else{
                            that.prop("checked",!that.is(":checked"));
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            })
            //删除
            $(".delete").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '确定删除吗?',
                    text: "确定删除吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'delete_live','version_id'=>$_GPC['version_id'])}",
                            data:{id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });
        })
    })
</script>